package com.hongyue1.dey01;

public class SellTicket implements Runnable {
    int piao = 100;
    Object obj = new Object();
    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (piao > 0) {
                    System.out.println(Thread.currentThread().getName() + "卖了一张票：还剩" + (--piao) + "张票");
                }
            }
        }
    }
}
